package cn.shiro.shiroservice.moudle.db.service.impl;

import cn.shiro.shiroservice.common.utils.FileUtils;
import cn.shiro.shiroservice.moudle.db.mapper.BackupMapper;
import cn.shiro.shiroservice.moudle.db.mapper.DataBaseMapper;
import cn.shiro.shiroservice.moudle.db.service.BackupService;
import cn.shiro.shiroservice.moudle.db.service.BaseBackUpService;
import lombok.Getter;
import lombok.Setter;

import java.io.File;

/**
 * &#064;Time 2024 二月 星期五 11:10
 *
 * @author ShangGuan
 */
public class BackupServiceImpl implements BackupService {

    private final BackupMapper backupMapper;

    private final DataBaseMapper dataBaseMapper;

    @Getter
    @Setter
    private  BaseBackUpService baseBackUpService;

    public BackupServiceImpl(BackupMapper backupMapper, DataBaseMapper dataBaseMapper, BaseBackUpService baseBackUpService) {
        this.backupMapper = backupMapper;
        this.dataBaseMapper = dataBaseMapper;
        this.baseBackUpService = baseBackUpService;
    }

    @Override
    public String queryDatabaseInstallPath() {
        return backupMapper.queryDatabaseInstallPath();
    }

    @Override
    public void backupDatabase(String backupTableName, String path) {
        baseBackUpService = new SimpleBaseBackUpServiceImpl(backupMapper,dataBaseMapper,backupTableName,path);
        baseBackUpService.backup();
    }

    @Override
    public void importData(String path) {
        String content = FileUtils.readStr(new File(path));

    }

    public static void main(String[] args) {
        BackupServiceImpl backupService = new BackupServiceImpl(null,null, null);
        backupService.importData("/Users/apple/Desktop/cache/2024-02-03/sys_role.sql");
    }

}
